import Vue from 'vue'
import Router from 'vue-router'
// import store from '../store/index'
import MyHome from '@/pages/home/MyHome'
import Customer from '@/pages/customer/Customer'
import Consult from '@/pages/consult/Consult'
import MySelf from '@/pages/myself/MySelf'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'MyHome',
      component: MyHome
    },
    {
      path: '/customer',
      name: 'Customer',
      component: Customer
    },
    {
      path: '/consult',
      name: 'Consult',
      component: Consult
    },
    {
      path: '/myself',
      name: 'MySelf',
      component: MySelf
    }
    // {
    //   path: '/helloWorld',
    //   name: 'HelloWorld',
    //   component: HelloWorld,
    //   meta: {
    //     requireAuth: true // 添加该字段，表示进入这个路由是需要登录的
    //   }
    // }
  ]
})

// 注册全局钩子用来拦截导航
// router.beforeEach((to, from, next) => {
//   const token = store.state.token
//   if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
//     if (token) { // 通过vuex state获取当前的token是否存在
//       next()
//     } else {
//       console.log('该页面需要登陆')
//       next({
//         path: '/login'
//         // query: {redirect: to.fullPath} // 将跳转的路由path作为参数，登录成功后跳转到该路由
//       })
//     }
//   } else {
//     next()
//   }
// })
